import random

import pygame
import Allcard
import Fight_Enemies
import Mission_Buildup
import PublicTools
import time
import easygui as g


class myself(object):
    weight = 1
    username = "username"
    buildup = []  # 养成材料仓库
    buildup_num = 0  # 养成材料的序号数值
    equipment = []  # 装备仓库
    equipment_num = 0  # 装备数量序号

    def __init__(self, username):
        self.weight = 1
        self.username = username
        self.buildup_num = 0
        self.equipment_num = 0
        self.buildup = []
        self.equipment = []

    def get_buildup(self, buildup):
        self.buildup[self.buildup_num] = buildup
        self.buildup_num += 1

    def get_equipment(self, equipment):
        self.equipment[self.equipment_num] = equipment
        self.equipment_num += 1

    def use_buildup(self, order):  # order为使用的养成函数的序号
        # 使用效果
        self.weight = 1000  # 计算结果

    def use_equipemnt(self, order):
        self.weight = 100  # 效果


# 全局配置
pygame.init()
screen = pygame.display.set_mode((1120, 630))  # 屏幕尺寸
pygame.display.set_caption("card_game")  # 游戏标题
clock = pygame.time.Clock()  # 计时
bg_img = pygame.image.load("../Docs/images/b10.jpeg")  # 背景图片
bg_title = pygame.image.load("../Docs/images/title2.PNG")
scene = 0  # 目前显示的场景，0为主界面，1为养成界面，2为选关界面，3为战斗界面，4是卡牌界面，5是关于界面
chosen_mission = 0
user = myself("my")


def menu():
    button_size = (250, 80)
    screen.blit(pygame.transform.scale(bg_img, (1120, 630)), (0, 0))
    screen.blit(pygame.transform.scale(bg_title, (560, 200)), (280, 0))
    if PublicTools.button((300, 150), button_size, "开  始", 32, (390, 175), "../Docs/images/button3.png"):
        return 3
    if PublicTools.button((600, 150), button_size, "养  成", 32, (690, 175), "../Docs/images/button3.png"):
        return 1
    if PublicTools.button((300, 350), button_size, "卡  牌", 32, (390, 375), "../Docs/images/button3.png"):
        return 4
    if PublicTools.button((600, 350), button_size, "关  于", 32, (690, 375), "../Docs/images/button3.png"):
        return 5
    return 0


def main():
    pygame.mixer.init()
    pygame.mixer.music.load("../Docs/bgm.mp3")
    pygame.mixer.music.play(-1)
    button_size = (200, 50)
    global scene
    pb1 = pygame.image.load("../Docs/images/pb1.PNG")
    pb2 = pygame.image.load("../Docs/images/pb2.PNG")
    pb3 = pygame.image.load("../Docs/images/pb3.PNG")
    pb4 = pygame.image.load("../Docs/images/pb4.PNG")
    pb5 = pygame.image.load("../Docs/images/pb5.PNG")
    pb6 = pygame.image.load("../Docs/images/pb6.PNG")
    start_time = time.time()
    showflag=0
    while True:
        screen.fill((255,255,255))
        if showflag==0:
            screen.blit(pb1, (140, 160))
            screen.blit(pb2, (140, 360))
        elif showflag==1:
            screen.blit(pb3, (140, 160))
            screen.blit(pb4, (140, 360))
        elif showflag==2:
            screen.blit(pb5, (140, 160))
            screen.blit(pb6, (140, 360))
        elif showflag>=3:
            break
        if PublicTools.button((850, 500), button_size, "下一步", 18, (920, 515), "../Docs/images/button3.png"):
            showflag += 1
        # end_time = time.time()
        # print(end_time-start_time)
        # if 0 <= end_time - start_time < 3:
        #     screen.blit(pb1, (140, 160))
        #     screen.blit(pb2, (140, 360))
        # elif 3 <= end_time - start_time < 6:
        #     screen.blit(pb3, (140, 160))
        #     screen.blit(pb4, (140, 360))
        # elif 6 <= end_time - start_time < 9:
        #     screen.blit(pb5, (140, 160))
        #     screen.blit(pb6, (140, 360))
        # else:
        #     break
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                exit()
        pygame.display.update()  # 更新画面

    while True:
        clock.tick(60)  # 刷新率
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                exit()

        if scene == 0:
            scene = menu()
        elif scene == 1:
            scene = Mission_Buildup.buildup()
        elif scene == 2:
            scene = Mission_Buildup.mission()
        elif scene == 3:
            scene = Fight_Enemies.fight()
        elif scene == 4:
            scene = Allcard.getcard()
        pygame.display.update()  # 更新画面


if __name__ == "__main__":
    main()
